﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using System.Windows.Markup;

namespace Invini.Training
{
    public enum TrainingInfoButton
    {
        None,
        Continue,
        OK,
        Start,
        Quit
    }
    public enum TrainingInfoPlacement
    {
        Left,
        Top,
        Right,
        Bottom,
        Center
    }
    public class TrainingInfoButtonClickedEventArgs
    {
        public TrainingInfoButton Button
        {
            get;
            private set;
        }

        public TrainingInfoButtonClickedEventArgs(TrainingInfoButton button)
        {
            this.Button = button;
        }
    }
    public delegate void TrainingInfoButtonClickedEventHandler(TrainingInfo info, TrainingInfoButtonClickedEventArgs e);
    public class TrainingInfo : ContentControl
    {
        public event TrainingInfoButtonClickedEventHandler ButtonClicked;

        public static readonly DependencyProperty ButtonProperty = DependencyProperty.Register("Button", typeof(TrainingInfoButton), typeof(TrainingInfo), new PropertyMetadata(TrainingInfoButton.None));
        public TrainingInfoButton Button
        {
            get { return (TrainingInfoButton)this.GetValue(ButtonProperty); }
            set { this.SetValue(ButtonProperty, value); }
        }

        public static readonly DependencyProperty PlacementProperty = DependencyProperty.Register("Placement", typeof(TrainingInfoPlacement), typeof(TrainingInfo));
        public TrainingInfoPlacement Placement
        {
            get { return (TrainingInfoPlacement)this.GetValue(PlacementProperty); }
            set { this.SetValue(PlacementProperty, value); }
        }

        static TrainingInfo()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TrainingInfo), new FrameworkPropertyMetadata(typeof(TrainingInfo)));
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            Button button = this.GetTemplateChild("button") as Button;
            if(button != null)
                button.Click += this.button_Click;
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (this.ButtonClicked != null)
                this.ButtonClicked(this, new TrainingInfoButtonClickedEventArgs(this.Button));
        }
    }
}
